package BuyerAgent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import main.MainFrame;
import main.RunTimeStarter;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * This class is the GUI for the report purchase that buyer agent shows the user
 * 
 * @author DUY HAN PHAN
 * 
 */
public class ReportGUI extends JFrame {

	private JPanel contentPane;
	private JTable wishListTable;
	private final JSeparator separator = new JSeparator();
	private JLabel lblReport;
	private Buyer buyerAgent;
	public volatile JTextArea txtReport;

	/**
	 * Create the frame.
	 */
	public ReportGUI(Buyer buyerAgentInstance) {
		setResizable(false);
		this.buyerAgent = buyerAgentInstance;

		setTitle("Report Purchase For " + buyerAgent.agentLocalName);

		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 578, 509);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 29, 552, 174);
		contentPane.add(scrollPane);

		wishListTable = new JTable();
		scrollPane.setViewportView(wishListTable);
		wishListTable.setModel(new WishListModelTable(buyerAgent.wishList));

		JLabel lblTheRestOf = new JLabel("The rest of wish list");
		lblTheRestOf.setBounds(10, 11, 201, 14);
		contentPane.add(lblTheRestOf);
		separator.setBounds(0, 216, 572, 14);
		contentPane.add(separator);

		lblReport = new JLabel("Report is saved in file " + "Report" + buyerAgent.agentLocalName + ".txt");
		lblReport.setBounds(10, 229, 455, 14);
		contentPane.add(lblReport);

		JButton btnExit = new JButton("EXIT");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
				// TODO do the same for seller!!!!!!!!!!!!!!!!!!!!!!!!!
				MainFrame.runningBuyerList.remove(buyerAgent.agentLocalName);
				buyerAgent.doDelete();
			}
		});
		btnExit.setBounds(462, 223, 98, 26);
		contentPane.add(btnExit);

		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(10, 255, 552, 214);
		contentPane.add(scrollPane_1);

		txtReport = new JTextArea();
		scrollPane_1.setViewportView(txtReport);
		txtReport.setFont(new Font("Dialog", Font.PLAIN, 10));
		txtReport.setLineWrap(true);
		txtReport.setEditable(false);
	}
}
